export function handleDate(firstDa) {
  if (!firstDa) return false
  const diffTime = new Date().getTime() - new Date(firstDa).getTime();
  const diffDays = Math.floor(diffTime / (24 * 60 * 60 * 1000))
  // const diffHours = Math.floor((diffTime % (24 * 60 * 60 * 1000)) / (60 * 60 * 1000))
  return diffDays
}

export function groupAndSortByDateDescending(array, dateKey) {
  const sortedArray = array.sort((a, b) => new Date(b[dateKey]) - new Date(a[dateKey]))
  const grouped = sortedArray.reduce((result, item) => {
    const date = item[dateKey].split('T')[0]
    if (!result[date]) {
      result[date] = []
    }
    result[date].push(item)
    return result
  }, {})
  return grouped
}
